<template>
  <div class="room-content">
    <Navbar :appTitle="appTitle" />
    <Search
      ref="topSearch"
      class="search"
      placeholder="物品名称|批号"
      :isScreen="true"
      :isType="true"
      @onSearch="onSearch"
      @onScreen="onScreen"
      @newBuild="newBuild"
    >
      <div slot="rightText">
        <div
          class="pubBtn"
          @click.stop="printGoodsInfo(false)"
          v-has="'goodBatchCode:batchPrint'"
        >
          批量打印
        </div>
      </div>
    </Search>
    <search-tag ref="SearchTag" @getCategory="getCategory"></search-tag>
    <!--分页列表 -->
    <div class="listBox">
      <pageList
        ref="pageList"
        :checkedShow="false"
        :columns="columns"
        :minLen="3"
        :listUrl="listUrl"
        @handleList="handleList"
      >
        <div slot="label" slot-scope="{ item }" class="label">
          <span class="pubBtn">{{ item.unitName }}</span>
          <span class="pubBtn">{{ item.produceDate }}</span>
          <span class="pubBtn">{{ item.batchCode }}</span>
        </div>
        <div slot="foot" slot-scope="{ item }" class="operateBox">
          <div
            class="pubBtn"
            @click.stop="printGoodsInfo(item)"
            v-has="'goodBatchCode:print'"
          >
            打印
          </div>
        </div>
      </pageList>
    </div>
  </div>
</template>
<script>
import Navbar from "@/components/navBar/navBar_right";
import Search from "@/components/search";
import SearchTag from "./SearchTag";
import pageList from "@/components/pageList";
import { Dialog } from "vant";
import { deleteItask } from "@/api/inventoryOrder";

export default {
  name: "inventoryCheckOrder",
  components: {
    Navbar,
    Search,
    SearchTag,
    pageList,
  },
  data() {
    return {
      appTitle: "物品批号",
      listUrl: "/wmsgoodsbatch/queryByPage", //列表接口
      columns: {
        titleKey: "goodsCode", //标题realtimeInventoryScope
        subtitleKey: "goodsName",
        thtitleKey: "spec",
        content: [
          //内容
          {
            name: "包装规格",
            key: ["packageSpec"],
          },
          {
            name: "产地",
            key: ["address"],
          },
          {
            name: "库存总数",
            key: ["totalGoodsNum"],
          },
        ],
      },
    };
  },
  beforeRouteLeave(to, from, next) {
    if (this.$refs.SearchTag.showSearchTag) {
      this.appTitle = this.$route.query.navTitle;
      this.$refs.SearchTag.showSearchTag = false;
      next(false);
    } else {
      next();
    }
  },
  mounted() {
    this.searchQuery();
  },
  methods: {
    // 搜索
    searchQuery(searchObj) {
      let params = {
        ...searchObj,
      };
      this.$refs.pageList.searchQuery(params);
    },
    // 模糊查询
    onSearch(v) {
      this.keyword = v;
      let searchObj = {
        keyWord: this.keyword,
      };
      this.searchQuery(searchObj);
    },
    // 更多查询页面
    onScreen() {
      this.appTitle = "更多筛选";
      this.keyword = this.$refs.topSearch.value;
      this.$refs.SearchTag.showModal(this.keyword);
    },
    getCategory(sureObj) {
      this.appTitle = "物品批号";
      this.keyword = sureObj.keyword;
      this.$refs.topSearch.value = sureObj.keyword;
      this.searchQuery(sureObj);
    },
    // 新建
    newBuild() {
      this.$router.push({
        path: "/inventoryRulesForm",
      });
    },
    //详情
    handleList(id, item, type) {
      return;

      this.$router.push({
        path: "/outboundOrderDetail",
        query: {
          id: item.id,
        },
      });
    },
    //打印
    printGoodsInfo(e) {
      if (e) {
        this.$router.push({
          name: "goodsPrintPage",
          params: {
            ...e,
          },
        });
      } else {
        this.$router.push({
          path: "/goodsBatchPrintList",
          query: {
            id: e.goodsId,
          },
        });
      }
    },
  },
};
</script>
<style lang="less" scoped>
.flex(@jc,@ai,@fd:row) {
  display: flex;
  justify-content: @jc;
  align-items: @ai;
  flex-direction: @fd;
}
.search {
  position: fixed;
  top: 93px;
  z-index: 98;
  width: 100%;
}
.listBox {
  margin-top: 120px;
  overflow-y: hidden;
}
.room-content {
  height: 100vh;
  overflow-y: scroll;
  .serach {
    height: 0.33rem;
    background: #f2f2f6;
    border-radius: 0rem;
    margin-bottom: 0.16rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 0.33rem;
    padding: 0.1rem 0.12rem;
    .placeh {
      font-size: 0.16rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #888888;
      line-height: 0.23rem;
    }
    .icon {
      width: 0.15rem;
      height: 0.16rem;
    }
  }
}
.operateBox {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  box-sizing: border-box;
  padding-right: 3px;
  font-size: 28px;
  font-weight: 500;
  color: #1890ff;
}
.label {
  margin-left: -6px;
  margin-top: -20px;
  span {
    height: 32px;
    background: #f0f6fe;
    color: #1890ff;
    margin-right: 20px;
    padding: 6px 16px;
    font-size: 22px;
    border-radius: 6px;
  }
  .UN {
    background-color: #e6e6e6;
    color: #969696;
  }
  .ING {
    background: #f0f6fe;
    color: #1890ff;
  }
  .PENDING {
    background-color: #fff5e6;
    color: #ff9900;
  }
  .FINISH {
    background-color: #e8f9f0;
    color: #19be6b;
  }
}
.pubBtn {
  margin-right: 20px;
  &:nth-last-child(1) {
    margin-right: 0;
  }
}
</style>
